//
//  videoplaycell.m
//  
//
//  Created by 吴志强 on 2019/6/3.
//

#import "videoplaycell.h"

@interface videoplaycell ()
@property (nonatomic,strong) AVPlayer *player;
@property (nonatomic,strong) AVPlayerLayer *videoLayer;

@end

@implementation videoplaycell

- (void) setview
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handlekillvideo) name:@"killvideo" object:nil];
}

- (void) handlekillvideo{

    [self.player pause];
    [self.player replaceCurrentItemWithPlayerItem:nil];
    self.player = nil;
    self.videoLayer = nil;
}

- (void) setVideo_url:(NSString *)video_url
{
    _video_url = video_url;

    //创建播放器
    AVPlayer *player = [AVPlayer playerWithURL:[NSURL URLWithString:video_url]];
    self.player = player;

        // 显示图像的
    _videoLayer = [AVPlayerLayer playerLayerWithPlayer:self.player];
        //锚点的坐标
    _videoLayer.frame = CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, 200);
    _videoLayer.backgroundColor = [UIColor blackColor].CGColor;
        //Layer只能添加到Layer上面
    [self.contentView.layer addSublayer:_videoLayer];

    [player play];
}


@end
